package com.mwf.types.design.framework.tree;

import lombok.Getter;
import lombok.Setter;

public abstract class AbstractStrategyRouter<T,D,R> implements StrategyMapper<T,D,R>,StrategyHandler<T,D,R>{

    @Getter
    @Setter
    protected StrategyHandler<T,D,R> defaultStrategyHandle = StrategyHandler.DEFAULT;

    public R router(T requestParameter,D dynamicContext) throws Exception {
        StrategyHandler<T, D, R> strategyHandler = get(requestParameter, dynamicContext);
        if (strategyHandler != null) return strategyHandler.apply(requestParameter, dynamicContext);;
        return defaultStrategyHandle.apply(requestParameter, dynamicContext);
    }

}
